// pages/center/withdraw-apply/withdraw-apply.js
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    array: ['微信', '银行卡', '支付宝'],
    array_index:[3,1,2],
    accmon:'',
    inputmon:'',
    index:0,
    type: 3,
    bank:'',
    bank_h:true,
    name:'',
    account:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.setNavigationBarTitle({
      title: '提现申请',
    })
  },
  bindPickerChange: function (e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    let that = this;
    this.setData({
      type: that.data.array_index[e.detail.value],
      index: e.detail.value
    });
    if(this.data.type == 1){
      this.setData({
        bank_h: false
      });
    }else{
      this.setData({
        bank_h: true
      });
    }
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    //获取可提现金额
    let that = this;
    app.post('/withdraw/getAccMoney').then(res=>{
      that.setData({
        accmon: res.normal
      })
    })
  },

  getAllMon:function(){
    let that = this;
    this.setData({
      inputmon: that.data.accmon,
    })
  },

  subMobel: function (e) {
    let that = this;
    let val = e.detail.value ? e.detail.value : 0
    if (parseFloat(val) <= parseFloat(that.data.accmon)){
      that.setData({
        inputmon: e.detail.value,
      })
    }else{
      that.setData({
        inputmon: that.data.accmon,
      })
    }
  },

  subMobel0: function (e) {
    this.setData({
      bank: e.detail.value,
    })
  },

  subMobel1:function(e){
    this.setData({
      name: e.detail.value,
    })
  },

  subMobel2: function (e) {
    this.setData({
      account: e.detail.value,
    })
  },

  comfirm: function(){
    let that = this
    if (that.data.inputmon <= 0){
      wx.showModal({
        title: '错误',
        content: '请检查提现金额',
      });
      return;
    }
    wx.showLoading({
      title: '提现中',
    })
    app.post('/withdraw/tixian',{
      type: that.data.type,
      name: that.data.name,
      account: that.data.account,
      money: that.data.inputmon,
      bank: that.data.bank
    }).then(res=>{
      wx.hideLoading();
      wx.showModal({
        title: '成功',
        content: '请等待审核',
        success: function(res){
          wx.navigateBack({});
        }
      })
      wx.navigateBack()
    },res=>{
      wx.hideLoading();
      wx.showModal({
        title: '失败',
        content: res,
        success: function (res) {
          wx.navigateBack({});
        }
      })
    })
  }

})